<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>水平居中布局解决方案1-text-align</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    /* 文本对齐:text-align */
    #child{
      text-align: center;
      background-color: blue;
    }
  </style>
</head>

<body>
  <!-- 定义父级元素 -->
  <div id="parent">
    <!-- 定义子级元素 -->
    <div id="child">居中布局</div>
  </div>
</body>

</html>